﻿using System;
using System.Xml.Serialization;

namespace BaseKeyWord
{
    class Program
    {
        static void Main(string[] args)
        {
            House house = new House();
            house.Mortgage = 100;
            Console.WriteLine("House中的值" + house.Liability);
            ThreeRoomHouse threeRoomHouse = new ThreeRoomHouse();
            house.Mortgage = 1000;
            Console.WriteLine("ThreeHouse中的值" + house.Liability);

            var stock = new Stock();
            Console.WriteLine(stock.Age);

            Stock stock1 = new Stock();
            Asset asset = stock1;
            stock1.Foo();
            asset.Foo();

            //测试子类构造函数
            Subclass subclass = new Subclass(123);
            Console.WriteLine(subclass.X);
        }
    }
    public class Asset
    {

        public virtual decimal Liability => 0;

        public int Age { get; set; } = 0;

        public void Foo()
        {
            Console.WriteLine("Asset.Foo");
        }
    }



    public class Stock : Asset
    {
        public long SharesOwned;

        public new int Age
        {
            get; set;
        } = 100;

        public new void Foo()
        {
            Console.WriteLine("new Foo");
        }
    }

    public class House : Asset
    {

        public decimal Mortgage;
        public override decimal Liability => base.Liability + Mortgage;

        public House()
        {
            Console.WriteLine("asset中的Liability" + base.Liability);
        }
    }

    public class ThreeRoomHouse : House
    {


        public override decimal Liability => base.Liability + Mortgage;

        public ThreeRoomHouse()
        {
            Mortgage = 100;
            Console.WriteLine("house中的Liability" + base.Liability);
        }
    }


    public class BaseClass
    {
        public int X;
        public BaseClass() { }

        public BaseClass(int x) { this.X = x; }
    }

    public class Subclass : BaseClass
    {

        public Subclass(int x) : base(x)
        {

        }
    }

}
